package com.fr.dialog.core;

import com.fr.base.Inter;
import com.fr.base.background.Background;
import com.fr.base.background.GradientBackground;
import com.fr.cell.core.GUICoreUtils;
import com.fr.cell.core.JNumberField;
import com.fr.dialog.BasicPane;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

public class GradientPane extends BasicPane
{
  private static final long serialVersionUID = -6854603990673031897L;
  private JRadioButton left2right;
  private JRadioButton top2bottom;
  private JComboBox areaCombox;
  private JCheckBox cyclic;
  private JNumberField begin;
  private JNumberField finish;
  private JPanel sizePane;
  private ChangeListener changeListener = null;
  private CardLayout card;
  private ColorSelectionPane startColorPane;
  private ColorSelectionPane lastColorPane;
  DocumentListener docListener = new DocumentListener(this)
  {
    private final GradientPane this$0;

    public void changedUpdate()
    {
      this.this$0.fireChagneListener();
    }

    public void insertUpdate()
    {
      this.this$0.fireChagneListener();
    }

    public void removeUpdate()
    {
      this.this$0.fireChagneListener();
    }
  };
  ActionListener reviewListener = new ActionListener(this)
  {
    private final GradientPane this$0;

    public void actionPerformed()
    {
      this.this$0.fireChagneListener();
    }
  };
  private ItemListener areaListener = new ItemListener(this)
  {
    private final GradientPane this$0;

    public void itemStateChanged()
    {
      this.this$0.fireChagneListener();
      if (GradientPane.access$000(this.this$0).getSelectedIndex() == 0)
        GradientPane.access$200(this.this$0).show(GradientPane.access$100(this.this$0), "cell");
      else
        GradientPane.access$200(this.this$0).show(GradientPane.access$100(this.this$0), "customize");
    }
  };

  public GradientPane()
  {
    setLayout(new BorderLayout());
    JPanel localJPanel1 = new JPanel(new BorderLayout());
    add(localJPanel1, "North");
    JPanel localJPanel2 = new JPanel();
    localJPanel1.add(localJPanel2, "North");
    localJPanel2.setLayout(new GridLayout(0, 2, 2, 2));
    localJPanel2.setBorder(BorderFactory.createEmptyBorder(13, 13, 12, 12));
    JPanel localJPanel3 = new JPanel(new FlowLayout(0, 4, 0));
    localJPanel2.add(localJPanel3);
    localJPanel3.add(new JLabel(Inter.getLocText("Start") + Inter.getLocText("Position") + Inter.getLocText("Color") + ":"));
    JPanel localJPanel4 = new JPanel();
    localJPanel3.add(localJPanel4);
    localJPanel4.setLayout(new FlowLayout(0, 4, 0));
    this.startColorPane = new ColorSelectionPane(80);
    localJPanel4.add(this.startColorPane);
    this.startColorPane.setColor(Color.lightGray);
    JPanel localJPanel5 = new JPanel(new FlowLayout(0, 4, 0));
    localJPanel2.add(localJPanel5);
    localJPanel5.add(new JLabel(Inter.getLocText("After") + Inter.getLocText("Position") + Inter.getLocText("Color") + ":"));
    JPanel localJPanel6 = new JPanel();
    localJPanel5.add(localJPanel6);
    localJPanel6.setLayout(new FlowLayout(0, 4, 0));
    this.lastColorPane = new ColorSelectionPane(80);
    localJPanel6.add(this.lastColorPane);
    this.lastColorPane.setColor(Color.black);
    JPanel localJPanel7 = new JPanel();
    localJPanel1.add(localJPanel7, "Center");
    localJPanel7.setLayout(new FlowLayout(0, 4, 4));
    localJPanel7.add(new JLabel(Inter.getLocText("Gradient") + Inter.getLocText("PageSetup-Orientation") + ":"));
    localJPanel7.setBorder(BorderFactory.createEmptyBorder(13, 13, 12, 12));
    this.left2right = new JRadioButton(Inter.getLocText("PageSetup-Landscape"));
    localJPanel7.add(this.left2right);
    this.left2right.addActionListener(this.reviewListener);
    this.top2bottom = new JRadioButton(Inter.getLocText("PageSetup-Portrait"));
    localJPanel7.add(this.top2bottom);
    this.top2bottom.addActionListener(this.reviewListener);
    ButtonGroup localButtonGroup = new ButtonGroup();
    localButtonGroup.add(this.left2right);
    localButtonGroup.add(this.top2bottom);
    JPanel localJPanel8 = new JPanel(new BorderLayout());
    add(localJPanel8, "Center");
    JPanel localJPanel9 = new JPanel(new FlowLayout(0, 4, 4));
    localJPanel8.add(localJPanel9, "North");
    this.areaCombox = new JComboBox(new String[] { Inter.getLocText("Current") + Inter.getLocText("Choose") + Inter.getLocText("Filed"), Inter.getLocText("Custom") + Inter.getLocText("Filed") });
    localJPanel9.add(new JLabel(Inter.getLocText("Gradient") + Inter.getLocText("Filed") + Inter.getLocText("Set") + ":"));
    localJPanel9.add(this.areaCombox);
    this.sizePane = new JPanel();
    this.card = new CardLayout();
    this.sizePane.setLayout(this.card);
    JPanel localJPanel10 = new JPanel(new BorderLayout());
    localJPanel10.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Filed") + Inter.getLocText("Set") + "(" + Inter.getLocText("Unit") + ":" + Inter.getLocText("px") + ")", null));
    this.begin = new JNumberField(4);
    this.begin.getDocument().addDocumentListener(this.docListener);
    this.finish = new JNumberField(4);
    this.finish.getDocument().addDocumentListener(this.docListener);
    JPanel localJPanel11 = new JPanel(new FlowLayout(0, 4, 4));
    localJPanel11.add(new JLabel(Inter.getLocText("Start") + Inter.getLocText("Position") + ":"));
    localJPanel11.add(this.begin);
    JPanel localJPanel12 = new JPanel(new FlowLayout(0, 4, 4));
    localJPanel12.add(new JLabel(Inter.getLocText("After") + Inter.getLocText("Position") + ":"));
    localJPanel12.add(this.finish);
    JPanel localJPanel13 = new JPanel(new FlowLayout(0));
    this.cyclic = new JCheckBox(Inter.getLocText("Repeat") + Inter.getLocText("Show"));
    localJPanel13.add(this.cyclic);
    this.cyclic.addActionListener(this.reviewListener);
    localJPanel12.add(localJPanel13);
    localJPanel10.add(localJPanel11, "North");
    localJPanel10.add(localJPanel12, "Center");
    JLabel localJLabel = new JLabel(Inter.getLocText("According_Cell_Set_Size"));
    JPanel localJPanel14 = new JPanel(new FlowLayout(0));
    localJPanel14.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Cell") + Inter.getLocText("Field"), null));
    localJPanel14.add(localJLabel);
    this.sizePane.add(localJPanel14, "cell");
    this.sizePane.add(localJPanel10, "customize");
    localJPanel8.add(this.sizePane, "Center");
    this.areaCombox.addItemListener(this.areaListener);
    defaultSetting();
  }

  private void defaultSetting()
  {
    this.left2right.setSelected(true);
    this.areaCombox.setSelectedIndex(0);
    this.begin.setValue(0.0D);
    this.finish.setValue(0.0D);
    this.card.show(this.sizePane, "cell");
  }

  public void populate(Background paramBackground)
  {
    if (!(paramBackground instanceof GradientBackground))
      return;
    GradientBackground localGradientBackground = (GradientBackground)paramBackground;
    this.startColorPane.setColor(localGradientBackground.getColor1());
    this.lastColorPane.setColor(localGradientBackground.getColor2());
    if (localGradientBackground.getDirection() == GradientBackground.LEFT2RIGHT)
      this.left2right.setSelected(true);
    else
      this.top2bottom.setSelected(true);
    if (localGradientBackground.isUseCell())
    {
      this.areaCombox.setSelectedIndex(0);
      return;
    }
    this.areaCombox.setSelectedIndex(1);
    this.begin.setValue(localGradientBackground.getBeginPlace());
    this.finish.setValue(localGradientBackground.getFinishPlace());
    this.cyclic.setSelected(localGradientBackground.isCyclic());
  }

  public GradientBackground update()
  {
    GradientBackground localGradientBackground = new GradientBackground();
    localGradientBackground.setColor1(this.startColorPane.getColor());
    localGradientBackground.setColor2(this.lastColorPane.getColor());
    if (this.left2right.isSelected())
      localGradientBackground.setDirection(GradientBackground.LEFT2RIGHT);
    else
      localGradientBackground.setDirection(GradientBackground.TOP2BOTTOM);
    if (this.areaCombox.getSelectedIndex() == 0)
    {
      localGradientBackground.setUseCell(true);
      return localGradientBackground;
    }
    localGradientBackground.setUseCell(false);
    localGradientBackground.setBeginPlace((float)this.begin.getValue());
    localGradientBackground.setFinishPlace((float)this.finish.getValue());
    localGradientBackground.setCyclic(this.cyclic.isSelected());
    return localGradientBackground;
  }

  public void addChangeListener(ChangeListener paramChangeListener)
  {
    this.changeListener = paramChangeListener;
  }

  public void fireChagneListener()
  {
    if ((this.startColorPane.getColor() == null) || (this.lastColorPane.getColor() == null))
      return;
    if (this.changeListener != null)
    {
      ChangeEvent localChangeEvent = new ChangeEvent(this);
      this.changeListener.stateChanged(localChangeEvent);
    }
  }

  static JComboBox access$000(GradientPane paramGradientPane)
  {
    return paramGradientPane.areaCombox;
  }

  static JPanel access$100(GradientPane paramGradientPane)
  {
    return paramGradientPane.sizePane;
  }

  static CardLayout access$200(GradientPane paramGradientPane)
  {
    return paramGradientPane.card;
  }
}